class Group < ActiveRecord::Base
  validates_presence_of :title
  format_attribute :content
  
  after_create {|g| Moderatorship.create(:group_id => g.id, :user_id => g.creator_id)}
  
  belongs_to :creator, :class_name => "User", :foreign_key => "creator_id"
  has_many :topics, :order => "sticky desc, replied_at desc", :dependent => :delete_all
  
  has_many :moderatorships, :dependent => :delete_all
  has_many :moderators, :through => :moderatorships, :source => :user
  
  
  def editable_by?(user)
    user!=:false && (user.id == creator_id || user.is_admin? || user.moderator_of?(self))
  end
  
  protected

end
